local jigu = fk.CreateSkill {
  name = "lingling__jigu",
}

Fk:loadTranslationTable{
  ["lingling__jigu"] = "激鼓",
  [":lingling__jigu"] = "结束阶段，你可以弃置X张牌，依次视为使用X张雷【杀】（X为你本回合发动的其他技能数）。",

  ["#lingling__jigu-invoke"] = "激鼓：你可以弃置%arg张牌，依次视为使用等量张雷【杀】！",
  ["#lingling__jigu-slash"] = "激鼓：你可以视为使用雷【杀】（第%arg张，共%arg2张）！",
}

jigu:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(jigu.name) and player.phase == Player.Finish and
      #player:getTableMark("lingling__jigu-turn") > 0 and #player:getCardIds("he") >= #player:getTableMark("lingling__jigu-turn")
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local n = #player:getTableMark("lingling__jigu-turn")
    local cards = room:askToDiscard(player, {
      min_num = n,
      max_num = n,
      include_equip = true,
      skill_name = jigu.name,
      prompt = "#lingling__jigu-invoke:::"..n,
      cancelable = true,
      skip = true,
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #player:getTableMark("lingling__jigu-turn")
    room:throwCard(event:getCostData(self).cards, jigu.name, player, player)
    if player.dead then return end
    for i = 1, n do
      if player.dead or not room:askToUseVirtualCard(player, {
        name = "thunder__slash",
        skill_name = jigu.name,
        prompt = "#lingling__jigu-slash:::" .. i..":"..n,
        cancelable = true,
        extra_data = {
          bypass_times = true,
          extraUse = true,
        },
      }) then
        break
      end
    end
  end,
})

jigu:addEffect(fk.AfterSkillEffect, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(jigu.name, true) and player.room.current == player and
      data.skill:isPlayerSkill(target) and not data.skill.is_delay_effect and
      data.skill.name ~= jigu.name
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addTableMarkIfNeed(player, "lingling__jigu-turn", data.skill:getSkeleton().name)
  end,
})

return jigu
